package tichu_project252.View.Player;

import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import tichu_project252.CardClasses.Card;
import tichu_project252.Controller.chooseCards;
import tichu_project252.Model.Model;


/**This class implements the player cards. 
 * The cards one player have are represented as buttons.
 *
 *
 * @author Alexandra Barka, ΑΜ: 2867, login : barka.
 * @version %I%, %G%
*/

public class PlayerCards extends JButton {

    private Card card = null;
    
/**
     * Constructs player cards..
     * 
     * 
     * <p><b>Constructor: </b> PlayerCards(Model m, Card c, int i) </p>
     *
     * <p><b>Precondition: </b> </p> <p><b>Postcondition: </b> Constructs a new
     * JButton </p>
     * 
     * @param m The model
     * @param   c The card we want create the button
     * 
     */
    public PlayerCards(Model m, Card c) throws IOException {
        super();
        
        this.card = c;
        Image image = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource(card.getImage()));
        //ImageIcon img = new ImageIcon(getClass().getResource(card.getImage()));
        ImageIcon img = new ImageIcon(image);
        int height = img.getIconHeight();
        int width = img.getIconWidth();
        this.setPreferredSize(new Dimension(width, height));
        this.setSize(7, 10);
        this.setIcon(img);
        this.addActionListener(new chooseCards(m));
    }

    /**
     * Returns the card.
     * Accessor
     * Post-condtion: Returns the card
     * 
     * @return card
     */

    public Card getCard() {
        return card;
    }
}
